import request from '@/utils/request'
import { praseStrEmpty } from "@/utils/ruoyi";

// 查询用户列表
export function listUser(query) {
  return request({
    url: '/sysUser/list',
    method: 'get',
    params: query
  })
}
// 获取roles
export function getRoles() {
  return request({
    url: '/sysUser/getRoles',
    method: 'get'
  })
}
// 查询用户详细
export function getInfo(userId) {
  return request({
    url: '/sysUser/getInfo',
    method: 'post',
    data: {id: userId}
  })
}

// 新增用户
export function addUser(data) {
  return request({
    url: '/sysUser/create',
    method: 'post',
    data: data
  })
}

// 修改用户
export function updateUser(data) {
  return request({
    url: '/sysUser/update',
    method: 'post',
    data: data
  })
}

// 删除用户
export function delUser(ids) {
  const data = {
    ids
  }
  console.log(ids);
  return request({
    url: '/sysUser/delete',
    method: 'post',
    data: data
  })
}

// 导出用户
export function exportUser(query) {
  return request({
    url: '/sysUser/export',
    method: 'get',
    params: query
  })
}

// 用户密码重置
export function resetUserPwd(id, pwd) {
  const data = {
    id,
    pwd
  }
  return request({
    url: '/sysUser/resetPwd',
    method: 'POST',
    data: data
  })
}

// 用户状态修改
export function changeUserStatus(userId, status) {
  console.log(status);
  const data = {
    userId,
    status
  }
  return request({
    url: '/sysUser/changeUserStatus',
    method: 'post',
    data: data
  })
}

// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: '/person/getInfo',
    method: 'get'
  })
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/user/profile',
    method: 'put',
    data: data
  })
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword
  }
  return request({
    url: '/person/updatePwd',
    method: 'get',
    params: data
  })
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: '/person/updateAvatar',
    method: 'post',
    data: data
  })
}

// 下载用户导入模板
export function importTemplate() {
  return request({
    url: '/user/importTemplate',
    method: 'get'
  })
}

// 查询授权角色
export function getAuthRole(id) {
  return request({
    url: '/sysUser/authRole' ,
    method: 'post',
    data: id
  })
}

// 保存授权角色
export function updateAuthRole(data) {
  return request({
    url: '/sysUser/insertAuthRole',
    method: 'post',
    data: data
  })
}
